import {defineStore} from 'pinia'
import {computed, ref} from 'vue'

// 定义仓库
export const useCounterStore =  defineStore('counter', () => {
    // 声明数据 state
    const count = ref(100)

    // 声明操作数据 action
    const addCount = () => count.value++
    const subCount = () => count.value--

    // 声明基于数据派生的计算属性 getters
    const double = computed(()=>count.value * 2)

    const msg = ref('hello pinia')

    return {
        count,
        msg,
        addCount,
        subCount,
        double
    }

},{
     // persist:true // 开启当前模块持久化
     persist: {
        key: 'hm-counter',
        pick:['count']
     }
})